home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / LOGFILE.C < prev    next >
Text File  |  1993-08-09  |  841b  |  40 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. main(argc,argv)
  6. int argc;
  7. char *argv[];
  8. {
  9.     char *logfile, line[256];
  10.     int maxlen = 0;
  11.     FILE *fp, *tp;
  12.  
  13.     if(argc > 1) {
  14.         logfile = argv[1];
  15.     } else {
  16.         logfile = "nos.log";
  17.     }
  18.  
  19.     if((fp = fopen(logfile,"rt")) == 0) {
  20.         fprintf(stderr,"%s can't open %s: %s\n\r",argv[0],logfile,sys_errlist[errno]);
  21.         exit(1);
  22.     }
  23.  
  24.     if((tp = fopen("log.new","wt")) == 0) {
  25.         fprintf(stderr,"%s can't open log.new: %s\n\r",argv[0],sys_errlist[errno]);
  26.         fclose(fp);
  27.         exit(1);
  28.     }
  29.  
  30.     while(fgets(line,sizeof(line),fp),!feof(fp)) {
  31.         if(strlen(line) > maxlen)
  32.             maxlen = strlen(line);
  33.         if(strstr(line,"Shutdown") == 0 && strstr(line,"Startup") == 0)
  34.             fputs(line,tp);
  35.     }
  36.     fclose(fp);
  37.     fclose(tp);
  38.     fprintf(stdout,"\n\rMax. line length %d\n\r",maxlen);
  39.     return;
  40. }